package com.huatai.manage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.query.RemoveQuery;
import com.huatai.manage.entity.TbSpecialEffectEntity;
import com.huatai.manage.service.TbSpecialEffectService;
import com.huatai.manage.utils.ComUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 特效管理; 前端控制器
 * </p>
 *
 * @author luoxc
 * @since 2023-03-21
 */
@RestController
@RequestMapping("effect")
@Api(value = "特效管理", tags = "特效管理")
public class TbSpecialEffectController {

	@Autowired
	private TbSpecialEffectService tbSpecialEffectService;


	@ApiOperationSupport(order = 1, includeParameters = {
		"pageQuery.current",
		"pageQuery.size",
		"pageQuery.data.effectName"
	})
	@PostMapping("pageList")
	@ApiOperation(value = "分页查询", notes = "分页查询")
	public R pageList(@RequestBody PageQuery<TbSpecialEffectEntity> pageQuery) {
		return R.data(this.tbSpecialEffectService.pageList(pageQuery));
	}

	@GetMapping("list")
	@ApiOperation(value = "查询所有数据", notes = "查询所有数据")
	public R list() {
		return R.data(this.tbSpecialEffectService.list());
	}

	@PostMapping("getByEffectId")
	@ApiOperation(value = "通过特效id查询单条数据", notes = "通过特效id查询单条数据")
	public R getOne(@ApiParam(name = "effectId", value = "特效id", required = true) @RequestParam("effectId") String effectId) {
		return R.data(this.tbSpecialEffectService.getByEffectId(effectId));
	}

	@PostMapping("getByTopicType")
	@ApiOperation(value = "通过特效类型查询数据", notes = "通过特效类型查询数据")
	public R getByTopicType(@ApiParam(name = "effectType", value = "特效id", required = true) @RequestParam("effectType") String effectType) {
		return R.data(this.tbSpecialEffectService.getByTopicType(effectType));
	}

	@PostMapping("insert")
	@ApiOperation(value = "新增数据", notes = "新增数据")
	public R insert(@Valid @RequestBody TbSpecialEffectEntity effectEntity) {
		return R.status(this.tbSpecialEffectService.save(effectEntity.setEffectId(ComUtil.getUUID())));
	}

	@PostMapping("update")
	@ApiOperation(value = "修改数据", notes = "修改数据")
	public R update(@Valid @RequestBody TbSpecialEffectEntity effectEntity) {
		return R.status(this.tbSpecialEffectService.update(effectEntity));
	}

	@PostMapping("removes")
	@ApiOperation(value = "批量删除", notes = "批量删除")
	public R removes(@RequestBody RemoveQuery remove) {
		return R.status(this.tbSpecialEffectService.removes(remove.getIds()));
	}

}
